package com.yf.dao;

import com.yf.bean.MessageBean;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class MessageDao extends BaseDao{
    public int addMessage(MessageBean msg) {
        return sessionTemplate.insert(getStatement("addMessage"), msg);
    }

    public List<MessageBean> getMsgByUid(Map<String, Object> params) {
        return sessionTemplate.selectList(getStatement("getMsgByUid"), params);
    }

    public int getMsgNum(Integer receiver) {
        return sessionTemplate.selectOne(getStatement("getMsgNum"), receiver);
    }

    public int getMsgNumUnRead(Integer uid) {
        Map<String, Object> params = new HashMap<>(2);
        params.put("uid", uid);
        params.put("status", 0);
        return sessionTemplate.selectOne(getStatement("getMsgNumUnRead"), params);
    }

    public int setMessageRead(Integer id) {
        Map<String, Object> params = new HashMap<>(2);
        params.put("id", id);
        params.put("status", 1);
        return sessionTemplate.update(getStatement("setMessageStatus"), params);
    }

    public int setMessageDisabled(Integer id) {
        Map<String, Object> params = new HashMap<>(2);
        params.put("id", id);
        params.put("status", 2);
        return sessionTemplate.update(getStatement("setMessageStatus"), params);
    }

    public List<MessageBean> getMsgById(List<Integer> ids) {
        return sessionTemplate.selectList(getStatement("getMsgById"), ids);
    }
}
